package shajie.shajun.mmhf.Adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import shajie.shajun.mmhf.Adapter.ViewHolder.DetailAdapterHolder;
import shajie.shajun.mmhf.Adapter.ViewHolder.OrderAdapterHolder;
import shajie.shajun.mmhf.Adapter.ViewHolder.OutGoods_Holder;
import shajie.shajun.mmhf.Adapter.ViewHolder.Re30OrderHolder;
import shajie.shajun.mmhf.Base.BaseRecyclerHolder;
import shajie.shajun.mmhf.Bean.Beans;
import shajie.shajun.mmhf.Bean2.OutGoods;
import shajie.shajun.mmhf.Bean2.Product;
import shajie.shajun.mmhf.R;
import shajie.shajun.mmhf.databinding.DialogOrderDetailBinding;
import shajie.shajun.mmhf.databinding.ItemOutgoosBinding;
import shajie.shajun.mmhf.databinding.ItemProductDetailBinding;
import shajie.shajun.mmhf.databinding.ItemSearchOrderBinding;

/**
 * Created by Administrator on 2017/11/16.
 */

public class MulRecyclerAdapter<T> extends RecyclerView.Adapter<BaseRecyclerHolder> {
    private Context mContext;
    public List<T> mDataList=new ArrayList<>();
    private int layoutid;
    public MulRecyclerAdapter(Context context, Beans<T> mDataList) {
        mContext=context;
        this.mDataList=mDataList.getBean();
        this.layoutid=mDataList.getItemViewType();
    }
    @Override
    public int getItemViewType(int position) {
        return layoutid;
    }

    @Override
    public BaseRecyclerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType){
            case R.layout.item_search_order:
                ItemSearchOrderBinding binding= DataBindingUtil.inflate(LayoutInflater.from(mContext), viewType,parent,false);
                return new OrderAdapterHolder(binding);
            case R.layout.item_product_detail:
                ItemProductDetailBinding binding2=DataBindingUtil.inflate(LayoutInflater.from(mContext), viewType,parent,false);
                return new DetailAdapterHolder(binding2,mDataList.size());
            case R.layout.dialog_order_detail:
                DialogOrderDetailBinding binding3=DataBindingUtil.inflate(LayoutInflater.from(mContext), viewType,parent,false);
                return new Re30OrderHolder(binding3);
            case R.layout.item_outgoos:
                ItemOutgoosBinding binding4=DataBindingUtil.inflate(LayoutInflater.from(mContext), viewType,parent,false);
                return new OutGoods_Holder(binding4);
        }
      return null;
    }

    @Override
    public void onBindViewHolder(BaseRecyclerHolder holder, int position) {
        holder.init(mDataList.get(position),position);
    }
    @Override
    public int getItemCount() {
        return mDataList == null ? 0 :mDataList.size();
    }
    public void changelist(Beans<T> beans){
        this.mDataList=beans.getBean();
        notifyDataSetChanged();
    }
    //产品
    public Product getItemProduct(int position){
      //  if (mDataList.get(position) instanceof Product) {
            return ((Product)mDataList.get(position));
       // }
    }
    public void setItemProduct(int position,int num){
        //  if (mDataList.get(position) instanceof Product) {
        ((Product)mDataList.get(position)).setInventory(num);
        notifyDataSetChanged();
        // }
    }

    //发货
    public void clearoutgoodsdata(){
        for (int i = 0; i < mDataList.size(); i++) {
            ((List<OutGoods>)mDataList).set(i,(OutGoods)mDataList.get(i)).setClear("True");
        }
        notifyDataSetChanged();
    }
    public OutGoods getOutGoods(int position){
        return (OutGoods)mDataList.get(position);
    }
    public void deleteOutGoods(int position){
        mDataList.remove(position);
        notifyDataSetChanged();
    }



}
